﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using RTC_Importer.Data;
using System.Reflection;
	
namespace RTC_Importer
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public partial class Converter_RTC
    {
        /// <summary>
        /// Tato metoda odpovida metode ParseDungeonTextFile v RTC
        /// </summary>
        /// <param name="filename"></param>
        public void ReadRTC(string filename)
        {
            RTC_MainData mainData;
            RTC_Description description;
            RTC_TextStrings textStrings;
			RTC_GraphicsInventBoxes graphicsInventBoxes;
			RTC_GraphicsMisc graphicsMisc;
			RTC_GraphicsInvent graphicsInventory;
			RTC_GraphicsInterface graphicsInterface;
			RTC_GraphicsEntrance graphicsEntrance;
			RTC_GraphicsUtility graphicsUtility;
			RTC_GraphicsFont graphicsFont;
			RTC_GraphicsMenus graphicsMenus;
			
			RTC_AudioMisc audioMisc;
			RTC_AudioRunes audioRunes;
			RTC_AudioParty audioParty;
			
			RTC_Party party;
			
			RTC_EndGameTextWinRepeat endGameTextWinRepeat;
			RTC_EndGameTextWinFirstTime endGameTextWinFirstTime;
			
            using (StreamReader sr = new StreamReader(filename))
            {
                string line = "";
                while ( ( line = sr.ReadLine() ) != null ) 
                {
                    if (line == "[Main Data]")
                        mainData = ParseMainData(sr);

					// no example, parsing reflects RTC code - 0.49
                    if (line == "[New - Sounds]")
                        ParseSounds(sr);

					// no example, parsing reflects RTC code - 0.49
                    if (line == "[New - Playlists]")
                        ParsePlaylists(sr);

					// no example, parsing reflects RTC code - 0.49
                    if (line == "[New - Bitmaps]")
                        ParseBitmaps(sr);

					// no example, parsing reflects RTC code - 0.49
                    if (line == "[New - Animations]")
                        ParseAnimations(sr);

                    if (line == "[New - Wallsets]")
                        ParseWallsets(sr);

                    if (line == "[New - Methods]")
                        ParseMethods(sr);

                    if (line == "[New - Spells]")
                        ParseSpells(sr);

                    if (line == "[New - Objects]")
                        ParseObjects(sr);

                    if (line == "[Description]")
                        description = ParseDescription(sr);

                    if (line == "[Text Strings]")
                        textStrings = ParseTextStrings(sr);

                    if (line == "[Audio - Party]")
                        audioParty = ParseAudioParty(sr);

                    if (line == "[Audio - Runes]")
                        audioRunes = ParseAudioRunes(sr);

                    if (line == "[Audio - Misc]")
                        audioMisc = ParseAudioMisc(sr);

                    if (line == "[Graphics - Menus]")
                        graphicsMenus = ParseGraphicsMenus(sr);

                    if (line == "[Graphics - Fonts]")
                        graphicsFont = ParseGraphicsFonts(sr);

                    if (line == "[Graphics - Utility]")
                        graphicsUtility = ParseGraphicsUtility(sr);

                    if (line == "[Graphics - Entrance]")
                        graphicsEntrance = ParseGraphicsEntrance(sr);

                    if (line == "[Graphics - Interface]")
                        graphicsInterface = ParseGraphicsInterface(sr);

                    if (line == "[Graphics - Inventory]")
                        graphicsInventory = ParseGraphicsInvent(sr);

                    if (line == "[Graphics - Inventory Boxes]")
                        graphicsInventBoxes = ParseGraphicsInventBoxes(sr);

                    if (line == "[Graphics - Misc]")
                        graphicsMisc = ParseGraphicsMisc(sr);

                    if (line == "[Characters]")
                        ParseCharacters(sr);

                    if (line == "[Party]")
                        party = ParseParty(sr);

                    if (line == "[Layout]")
                        ParseDungeonLayout(sr);

                    if (line == "[Items]")
                        ParseDungeonItems(sr);

                    if (line == "[Hint Oracle - Monsters]")
                        ParseHintOracleCreatures(sr);

                    if (line == "[Hint Oracle - Locations]")
                        ParseLocations(sr);

                    if (line == "[Hint Oracle - Objects]")
                        ParseHintOracleObjects(sr);

                    if (line == "[End Game Text - Win First Time]")
                        endGameTextWinFirstTime = ParseEndGameTextWinFirstTime(sr);

                    if (line == "[End Game Text - Win Repeat]")
                        endGameTextWinRepeat = ParseEndGameTextWinRepeat(sr);

                    if (line == "[End Game Text - Lose Dead]")
                        ParseEndGameTextLoseDead(sr);

                    if (line == "[End Game Text - Lose Time]")
                        ParseEndGameTextLoseTime(sr);

                    //unk
                }
            }
        }

        public void SetPropUsingRefl(object o, string key, string value)
        {
            PropertyInfo myProperty = null;
            foreach (PropertyInfo info in o.GetType().GetProperties())
            {
                if (info.Name==key)
                {
                    myProperty = info;
                    break;
                }
            }

            if (myProperty != null)
            {
                myProperty.SetValue(o, value, null);
            }

            //object myValue = "Something";
            //if (propertyInfo.CanWrite)
            //{
            //    this.propertyInfo.SetValue(myObject, myValue, null);
            //}


 
        }
    }
}
